home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / oldwish / wishGarbage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-11  |  3.7 KB  |  139 lines

  1. /* 
  2.  * wishGarbage.c --
  3.  *
  4.  *    Garbage collection routines.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /a/newcmds/wish/RCS/wishGarbage.c,v 1.3 89/01/11 11:59:36 mlgray Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21.  
  22. #ifndef AllPlanes
  23. #include "X11/Xlib.h"
  24. #endif
  25. #include "wishInt.h"
  26.  
  27.  
  28. /*
  29.  *----------------------------------------------------------------------
  30.  *
  31.  * WishGarbageCollect --
  32.  *
  33.  *    Garbage collection.
  34.  *
  35.  * Results:
  36.  *    None.
  37.  *
  38.  * Side effects:
  39.  *    Stuff is deallocated, destroyed, deleted and otherwise caused to
  40.  *    be missing.
  41.  *
  42.  *----------------------------------------------------------------------
  43.  */
  44. void
  45. WishGarbageCollect(aWindow)
  46.     WishWindow    *aWindow;
  47. {
  48.     WishGroup    *tmpGroupPtr;
  49.     WishGroup    *tmpNextGPtr;
  50.     WishSelection    *tmpSelPtr, *selPtr;
  51.  
  52.     WishClearWholeSelection(aWindow);
  53.     for (tmpGroupPtr = aWindow->groupList; tmpGroupPtr != NULL;
  54.         tmpGroupPtr = tmpNextGPtr) {
  55.     tmpNextGPtr = tmpGroupPtr->nextPtr;
  56.     WishGarbageGroup(aWindow, tmpGroupPtr);
  57.     }
  58.     aWindow->groupList = NULL;
  59.     aWindow->numElements = -1;
  60.     aWindow->numGroups = -1;
  61.     aWindow->numHiddenGroups = 0;
  62.     aWindow->firstElement = -1;
  63.     aWindow->lastElement = -1;
  64.     for (selPtr = aWindow->selectionList;
  65.         selPtr != NULL && selPtr->nextPtr != NULL; ) {
  66.     tmpSelPtr = selPtr->nextPtr;
  67.     free(selPtr);
  68.     selPtr = tmpSelPtr;
  69.     }
  70.     aWindow->totalDisplayEntries = 0;
  71.  
  72.     return;
  73. }
  74.  
  75.  
  76. /*
  77.  *----------------------------------------------------------------------
  78.  *
  79.  * WishGarbageGroup --
  80.  *
  81.  *    Garbage collection for a single group.  It frees the space for the
  82.  *    group structure as well as all resources allocated to the group.
  83.  *
  84.  * Results:
  85.  *    None.
  86.  *
  87.  * Side effects:
  88.  *    Stuff is deallocated, destroyed, deleted and otherwise caused to
  89.  *    be missing.
  90.  *
  91.  *----------------------------------------------------------------------
  92.  */
  93. void
  94. WishGarbageGroup(aWindow, grpPtr)
  95.     WishWindow    *aWindow;
  96.     WishGroup        *grpPtr;
  97. {
  98.     WishFile    *tmpFilePtr;
  99.     WishFile    *tmpNextFPtr;
  100.  
  101.     if (grpPtr->headerWindow != UNINITIALIZED && grpPtr->headerWindow != 0) {
  102.     XDeleteContext(wishDisplay, grpPtr->headerWindow,
  103.         wishGroupWindowContext);
  104.     XDeleteContext(wishDisplay, grpPtr->headerWindow,
  105.         wishWindowContext);
  106.     XDestroyWindow(wishDisplay, grpPtr->headerWindow);
  107.     }
  108.     if (grpPtr->fileList == NULL && aWindow->hideEmptyGroupsP) {
  109.     aWindow->numHiddenGroups--;
  110.     }
  111.     aWindow->numGroups--;
  112.     for (tmpFilePtr = grpPtr->fileList; tmpFilePtr != NULL;
  113.         tmpFilePtr = tmpNextFPtr) {
  114.     tmpNextFPtr = tmpFilePtr->nextPtr;
  115.     if (tmpFilePtr->name != NULL) {
  116.         free(tmpFilePtr->name);
  117.     }
  118.     aWindow->numElements--;
  119.     free(tmpFilePtr);
  120.     }
  121.     if (grpPtr->rule != NULL) {
  122.     free(grpPtr->rule);
  123.     }
  124.     WishDeleteGroupBindings(grpPtr);
  125.     free(grpPtr);
  126.  
  127.     /*
  128.      * Reset total number of visible elements to the number of files plus
  129.      * the number of headers for visible groups + the number of spaces
  130.      * between visible groups.  This calculation is performed in
  131.      * WishGatherNames() and WishGatherSingleGroup() as well, but garbage
  132.      * collection of a single group affects this number as well.
  133.      */
  134.     aWindow->totalDisplayEntries = aWindow->numElements +
  135.         (2 * (aWindow->numGroups - aWindow->numHiddenGroups)) - 1;
  136.  
  137.     return;
  138. }
  139.